package org.locker.device.controller.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.locker.common.core.domain.R;
import org.locker.common.core.validate.AddGroup;
import org.locker.common.mybatis.core.page.PageQuery;
import org.locker.common.satoken.utils.LoginHelper;
import org.locker.common.web.core.BaseController;
import org.locker.domain.bo.WithdrawBo;
import org.locker.domain.enums.WithdrawTypeEnum;
import org.locker.domain.vo.WithdrawVo;
import org.locker.service.IWithdrawService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *  (小程序)用户提现管理
 *
 * @author lark
 * @date 2023-10-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/withdraw")
public class WebWithdrawController extends BaseController {

    private final IWithdrawService withdrawService;

    /**
     * 查询提现列表
     */
    @GetMapping("/list")
    public R<Page<WithdrawVo>> list(WithdrawBo bo, PageQuery pageQuery) {
        bo.setUserId(LoginHelper.getUserId());
        return R.ok(withdrawService.queryPageList(bo, pageQuery));
    }


    /**
     * 提现(后期开放)
     * @param bo
     * @return
     */
    //@PostMapping("/add")
    public R<Long> add(@Validated(AddGroup.class) @RequestBody WithdrawBo bo) {
        bo.setUserId(LoginHelper.getUserId());
        return R.ok(withdrawService.insertByBo(bo));
    }

    /**
     * 提现-V2
     * @param orderNo
     * @return
     */
    @GetMapping("/add/{orderNo}")
    public R<Long> add(@PathVariable("orderNo") String orderNo) {
        Long userId = LoginHelper.getUserId();
        //Long userId = 1717128594751258626L;
        return R.ok(withdrawService.withdrawV2(userId,orderNo, WithdrawTypeEnum.SELF.getCode()));
    }
}
